<template>
	<view>
		<view class="edgeInsetTop"></view>
		<view class="wanl-order text-bold">
			<view class="address cu-list menu-avatar margin-bj radius-bock">
				<view class="cu-item">
					<view class="cu-avatar round wanl-bg-orange"><text class="wlIcon-weizhi1"></text></view>
					<view class="content" v-if="addressData.detailed_address" @tap="userAddress()">
						<view>
							<text class="wanl-pip margin-right-sm">{{ addressData.username }}</text>
							<text class=" text-sm">{{ addressData.mobile }}</text>
						</view>
						<view class="text-sm wanl-pip text-cut">{{ addressData.province_name}}
							{{ addressData.city_name }} {{ addressData.area_name }} {{ addressData.detailed_address }}
						</view>
					</view>
					<view class="content" @tap="userAddress()" v-else>
						<view class="text-sm wanl-pip text-cut">点击此处填写收货地址</view>
					</view>
					<view class="action"><text class="wlIcon-fanhui2 text-lg"></text></view>
				</view>
			</view>
			<view class="lists bg-white margin-bj radius-bock">
				<view class="shopname">
					<!-- <text class="wlIcon-dianpu2 text-orange margin-right-sm"></text> -->
					<!-- <text class="wanl-pip text-df">{{ shop.shop_name }}</text> -->
				</view>
				<view class="cu-list menu-avatar" v-for="(goods,index) in optionData" :key="index">
					<view class="cu-item margin-bottom">
						<view class="cu-avatar radius-bock"
							:style="{ backgroundImage: 'url(' + $wanlshop.oss(goods.cover, 77, 77) + ')' }"></view>
						<view class="content">
							<view class="text-sm text-cut-2">{{goods.title }}</view>
							<view class="wanl_sku text-sm">
								<text v-if="goods.good_sku">{{ goods.good_sku }}
								</text>
							</view>
						</view>
						<view class="action">
							<view class="wanl-pip text-sm text-price">{{ goods.current_price }}</view>
							<view class="wanl-gray-light text-sm">x{{ goods.good_num }}</view>
						</view>
					</view>
				</view>
			</view>
			<form>

				<view class="lists bg-white margin-bj radius-bock">


					<!-- <view class="cu-form-group" v-if="cartType">
						<view class="wanl-gray-light title">购买数量</view>
						<uni-number-box :min="1" :max="orderData.lists[0].products[0].sku.stock" :value="optionData.number" @change="changeNum"></uni-number-box>
					</view>
					<view class="cu-form-group">
						<view class="wanl-gray-light title">快递运费</view>
						<view class="picker"><text class="text-price margin-left-xs">{{orderData.freight_price}}</text></view>
					</view> -->
					<view class="cu-form-group" @tap="queryCoupon()">
						<view class="title">优惠折扣</view>
						<view class="picker">
							<block v-if="coupon_txt">
								<text class="wlIcon-youhuiquantuangou text-red margin-right-xs"></text>

								<block>
									<text>{{coupon_txt}}</text>
								</block>
							</block>
							<block v-else>
								<text class="text-gray">请选择</text>
							</block>
							<text class="wlIcon-fanhui2 margin-left"></text>
						</view>
					</view>

					<view class="cu-form-group">
						<view class="title ">提货方式</view>

						<picker @change="open_sel_way" :value="shipping_type" :range="shippingList" range-key="name">
							<view class="picker">
								<view class="flex justify-end align-center" v-if="shipping_type > -1">
									<!-- <image :src="`/static/images/bank/${bankList[index].bankCode}.png`"></image> -->
									<view class="margin-left-xs">{{shippingList[shipping_type].name}}</view>
								</view>
								<view v-else>
									请选择{{shipping_type}}
								</view>
							</view>
						</picker>
					</view>

				</view>

				<view class="lists bg-white margin-bj radius-bock">
					<view class="cu-form-group align-start">
						<view class=" title">商品小计</view>
						￥{{total.toFixed(2)}}
					</view>
					<view class="cu-form-group align-start">
						<view class=" title">配送费</view>
						￥{{freight_price.toFixed(2)}}
					</view>

					<view class="cu-form-group" v-if="shipping_type==1">
						<view class="title ">上楼服务(入户)<span style="color:#E90000;">(请务必如实填写)</span></view>
						<picker @change="open_sel_service" :value="sel_service" :range="serviceList" range-key="name">
							<view class="picker">
								<view class="flex justify-end align-center">
									<view class="margin-left-xs">
										{{sel_service>-1?serviceList[sel_service].name:'请选择'}}
									</view>
								</view>
							</view>
						</picker>
					</view>

					<view class="cu-form-group" v-if="sel_service>0 && shipping_type==1">
						<view class="title ">选择楼层</view>

						<picker @change="open_sel_floor" :value="sel_floor" :range="floorList" range-key="name">

							<view class="picker">
								<view class="flex justify-end align-center">
									<view class="margin-left-xs">
										{{sel_floor>-1?floorList[sel_floor].name:'请选择'}}
									</view>
								</view>
							</view>
						</picker>
					</view>
					<view class="cu-form-group align-start" v-if="sel_service==1">
						<view class=" title"></view>
						<span style="color:#E90000;text-align: right;">温馨提示：电梯2楼以上选择2楼即可</span>
					</view>
					<view class="cu-form-group align-start">
						<view class=" title">搬运费</view>
						￥{{ship_price.toFixed(2)}}
					</view>
					<view class="cu-form-group align-start">
						<view class=" title">优惠券</view>
						￥{{coupon_money}}
					</view>

				</view>


				<view class="lists bg-white margin-bj radius-bock">

					<view class="cu-form-group">
						<view class=" title">虚拟币抵扣，可用{{gold.toFixed(2)}}虚拟币，抵{{gold_money.toFixed(2)}}元
						</view>
						<span class="gold_opt" tapmode @click="is_used_gold = is_used_gold==0?1:0">
							<img v-if="is_used_gold=='0'&&orderData!='0'"
								src="https://zm.zonmay.com/public/static/wap/image/icon/icon-switch-off.png" />
							<img v-if="is_used_gold=='1'&&orderData!='0'"
								src="https://zm.zonmay.com/public/static/wap/image/icon/icon-switch-on.png" />
						</span>
						<!-- <div class="gold_none" v-if="orderData.is_used_gold=='0'"
							style="margin-top:0.3rem;font-size:0.65rem;font-family:PingFangSC-Regular;font-weight:400;color:rgba(102,102,102,1);">
							暂不可用
						</div> -->
					</view>

				</view>


				<view class="lists bg-white margin-bj radius-bock">
					<view class="cu-form-group align-start">
						<view class="title">备注</view>
						<textarea maxlength="100" v-model="remarks" placeholder="订单备注可选"></textarea>
					</view>
				</view>


			</form>
			<view class="text-right margin-bj text-sm">
				小计：
				<text
					class="text-price text-orange">{{price_format('yuan',amount)}}.{{price_format('fen',amount)}}</text>
			</view>
		</view>
		<view class="safeAreaBottom"> </view>
		<!-- 弹出层 -->
		<view class="WANL-MODAL text-sm" @touchmove.stop.prevent="moveHandle">
			<!-- 优惠券 -->

			<view class="cu-modal bottom-modal" :class="modalName == 'coupon' ? 'show' : ''" @tap="hideModal">
				<view class="cu-dialog bg-bgcolor" @tap.stop="">
					<view class="wanl-modal">
						<view class="head padding-bj">
							<view class="content">
								<view class="text-lg">优惠券{{modalName}}</view>
							</view>
							<view class="close wlIcon-31guanbi" @tap="hideModal"></view>
						</view>
						<scroll-view class="wanl-coupon scroll-y" scroll-y="true">
							<view v-for="(coupon, index) in couponList" :key="index" :class="coupon.type"
								class="item margin-bottom-bj radius-bock">
								<image :src="$wanlshop.appstc('/coupon/bg_coupon_3x.png')" class="coupon-bg">
								</image>
								<view class="item-left">
									<block v-if="coupon.coupon_type == '满减'">
										<view class="colour">
											<text class="text-price"></text>
											<text class="prices">{{Number(coupon.money)}}</text>
										</view>
										<view class="cu-tag wanl-gray-dark radius text-sm bg-white">
											满{{Number(coupon.full_money)}}减{{Number(coupon.money)}}
										</view>
									</block>

									<block v-if="coupon.coupon_type == '包邮'">
										<view class="colour">
											<text class="prices">包邮</text>
										</view>
										<view class="cu-tag wanl-gray-dark radius text-sm bg-white">
											包邮
										</view>
									</block>
								</view>
								<view class="item-right padding-bj">
									<view class="title">
										<view class="cu-tag sm radius margin-right-xs tagstyle">
											{{coupon.type_text}}
										</view>
										<text class="text-cut wanl-gray text-min">{{coupon.name}}</text>
									</view>
									<view class="content text-min">
										<view class="wanl-gray">


											<block>
												<view>
													<text class="wlIcon-dot"></text>生效 {{coupon.start_time}}
												</view>
												<view>
													<text class="wlIcon-dot"></text>结束 {{coupon.end_time}}
												</view>
											</block>

										</view>

										<view class="cu-btn sm round line-colour"
											@tap="onCoupons(coupon.id,coupon.money)">

											<text> 立即使用 </text>
										</view>
									</view>
								</view>
							</view>
						</scroll-view>
						<view class="foot padding-lr-bj"><button
								class="cu-btn bg-gradual-orange round text-bold complete" @tap="hideModal">完成</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="wanlian cu-bar tabbar solid-top foot text-df text-bold">
			<view class="margin-bj">

				合计：
				<text class="text-price text-red">{{price_format('yuan',amount)}}.{{price_format('fen',amount)}}</text>
			</view>
			<button v-if="loading" class="cu-btn round lg bg-gradual-orange margin-lr-bj">
				<text class="wlIcon-jiazai wlIconfont-spin margin-right-xs"></text> 提交中...
			</button>
			<button v-else-if="distance<50" @tap="addOrder" class="cu-btn round lg bg-gradual-orange margin-lr-bj">
				提交订单 </button>
			<button v-else class="cu-btn round lg bg-grey margin-lr-bj"> 提交订单 </button>

		</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				getGoodslist:[],
				couponList: [],
				amount: 0,
				// 客户爱好
				shippingList: [{
					"name": '上门自提',
					"id": 0
				}, {
					"name": '配送至楼下',
					"id": 1
				}],
				serviceList: [{
					"name": '不需要',
					"id": 0
				}, {
					"name": '有电梯',
					"id": 1
				}, {
					"name": '无电梯',
					"id": 2
				}],
				sel_price: {},
				shipping_type: 1,
				sel_service: -1,
				sel_floor_name: '1楼',
				sel_floor: -1,
				floorList: {},
				loading: false,
				reload: false,
				token: '',
				optionData: {},
				addressData: {},
				modalName: null, // 弹出层
				cartType: null,
				couponData: {},
				couponIndex: null,
				orderData: {},
				current_price: 0,
				id: 0,
				flag: 0, //2标识详情页发起生成订单，1标识购物车发起生成订单，3秒杀，4团购
				goods_info: [],
				order_info: {
					is_used_gold: 0
				}, //is_used_gold是否可使用商城币，gold商城币，gold_money抵扣金额
				good_address: {},
				coupon_txt: '暂无可用',
				coupon_money: 0,
				shipping_remark: '',
				is_used_gold: 0,
				gold: 0,
				gold_money: 0,
				gold_convert: 10,
				ship_price: 0,
				freight_price: 0,
				ship_type: '',
				is_used_coupon: 0,
				user_coupon_id: 0,
				max_length: 150,
				remarks: '',
				good_list: [], //[{"good_id":"1","good_num":"2","good_sku":"40寸|红"}]
				total: 0,
				miao_id: 0,
				tuan_id: 0,
				tuan_uid_pid: 0,
				is_receipt: 0,
				receipt_type: '未选择',
				receipt_person: '',
				receipt_name: '',
				receipt_num: '',
				currentCheck: true,
				current: false,
				total_amount: 0,
				distance: 0,
				address_id: 0,
				localcity: {
					"id": 2608,
					"parentid": 235,
					"categoryname": "托普·平邑仓",
					"spell": "pingyixian",
					"first_letter": "P"
				},
				region_name: '平邑县',
				gold: 0,
				gold_money: 0,
				total: 0,
			};
		},
		onLoad(option) {
			console.log(option.data)
			this.optionData = JSON.parse(option.data);
			this.loadData();
			this.cartType = option.type;

			var total = 0
			this.optionData.forEach(function(el, index) {
				// this.goods_info[index].good_sku = this.good_list[index].good_sku.split('|')
				total += el.current_price * el.good_num
			})
			this.total = total

			this.region_name = uni.getStorageSync("city_name");
			console.log(this.region_name);
			// alert(this.city_name)
		},
		onShow() {
			this.loading = false;
			// this.sel_floor = -1;
		},
		watch: {

			freight_price: function(new_str, old_str) {
				this.freight_price = new_str;
				var amount = 0;
				if (this.freight_price == 0) {
					amount = this.total * 100 + this.orderData.exp_fee
				} else {
					amount = this.total * 100 + this.orderData.exp_fee + this.freight_price
				}

				amount = amount / 100;
				this.amount = amount.toFixed(2)

				// send_event('order_amount', {
				// 	amount: amount,
				// 	distance: this.distance
				// })
			},

			orderData: function(new_str, old_str) {
				var amount = this.total * 100 + this.orderData.exp_fee + this.orderData.freight_price;
				console.log(amount)
				if (this.is_used_coupon) {
					// amount = amount - this.orderData.exp_fee;
					amount = amount - this.coupon_money * 100;
				}
				if (this.is_used_gold) {
					if (amount >= this.gold_money * 100) {
						amount = amount - this.gold_money * 100;
					} else {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
						amount = 0;
					}
				} else {
					if (amount < this.gold_money * 100) {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
					}
				}

				amount = amount / 100;
				this.amount = amount.toFixed(2)
				console.log(this.amount)
				// send_event('order_amount', {
				// 	amount: amount,
				// 	distance: this.distance
				// })
			},
			is_used_gold: function(new_str, old_str) {
				var amount = this.total * 100 + this.orderData.exp_fee + this.orderData.freight_price;
				if (this.is_used_coupon) {
					// amount = amount - this.orderData.exp_fee;
					amount = amount - this.coupon_money * 100;
				}
				// alert(amount)
				// alert(this.gold_money)
				if (this.is_used_gold) {
					if (amount >= this.gold_money * 100) {
						amount = amount - this.gold_money * 100;
					} else {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
						amount = 0;
					}
				} else {
					if (amount < this.gold_money * 100) {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
					}
				}

				amount = amount / 100;
				this.amount = amount.toFixed(2)
				// alert(amount)
				// send_event('order_amount', {
				// 	amount: amount,
				// 	distance: this.distance
				// })
			},
			ship_price: function(new_str, old_str) {
				var amount = this.total * 100 + this.orderData.exp_fee * 1 + new_str * 100;
				amount = amount / 100 + this.freight_price;

				this.amount = amount.toFixed(2)
				console.log(this.amount)
				// send_event('order_amount', {
				// 	amount: amount,
				// 	distance: this.distance
				// })
			},
			is_used_coupon: function(new_str, old_str) {
				var amount = this.total * 100 + this.orderData.exp_fee + this.orderData.freight_price;

				if (this.is_used_coupon) {
					// amount = amount - this.orderData.exp_fee;
					amount = amount - this.coupon_money * 100;
				}
				if (this.is_used_gold) {
					if (amount >= this.gold_money * 100) {
						amount = amount - this.gold_money * 100;
					} else {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
						amount = 0;
					}
				} else {
					if (amount < this.gold_money * 100) {
						this.gold_money = amount / 100;
						this.gold = amount / 100 * this.gold_convert
					}
				}
				amount = amount / 100;
				this.amount = amount.toFixed(2)
				// alert(this.amount)
				// send_event('order_amount', {
				// 	amount: amount,
				// 	distance: this.distance
				// })
			},
			mark: function(a, b) {
				if (this.mark.length > 150) {
					this.mark = b;
				}
			},


		},
		methods: {

			price_format: function(type, price) {
				var status = (price + '').indexOf('.')
				if (status == '-1') {
					if (type == 'yuan') {
						return price;
					}
					if (type == 'fen') {
						return '00';
					}
				}
				var price_array = (price + '').split('.')
				if (type == 'yuan') {
					return price_array[0];
				}
				if (type == 'fen') {
					var price_fen = price_array[1].length < 2 ? price_array[1] + '0' : price_array[1];
					return price_fen;
				}
			},
			// 配送类型
			open_sel_way(e) {

				let key = e.detail.value
				this.shipping_type = this.shippingList[key].id
				console.log(this.shippingList[key]);
				console.log("配送类型", this.shipping_type);
				if (this.shipping_type == 0) {
					this.sel_service = 0
					this.sel_floor = '0'
					this.sel_floor_name = '1楼'
					this.ship_price = 0
					this.shipping_remark = ''
					this.freight_price = 0
				}
				// alert(this.freight_price)
			},
			//上楼服务
			open_sel_service(e) {
				let _this = this;
				console.log(e);
				let key = e.detail.value;
				_this.sel_service = _this.serviceList[key].id
				console.log("上楼", _this.sel_service);
				if (e.detail.value > -1) {
					console.log(JSON.stringify(e.detail.value))
					// _this.sex = res.selectedInfo[0].name;
					// _this.updateUserInfo('sex', res.selectedInfo[0].id)
					_this.sel_service = _this.serviceList[key].id
					// alert(_this.sel_service)
					if (_this.sel_service == 0) {
						_this.ship_price = 0
						_this.shipping_remark = '不需要'
					} else {
						// _this.ship_price = (_this.total * _this.shipping_list[0].dianti * 0.01).toFixed(2)
						_this.ship_price = 0;
						_this.current_price = 0;

						// alert(JSON.stringify(_this.optionData));

						_this.optionData.forEach(function(el, index) {
							_this.current_price = (_this.optionData[index].current_price * _this.optionData[index]
								.good_num)
							// console.log(this.current_price)
							if (_this.sel_service == 1) {
								_this.getdiantiPrice(1,_this.optionData[index].peisong_type_id,_this.optionData[index].peisong_type_name);
							} else {
								_this.getnodiantiPrice(0,_this.optionData[index].peisong_type_id,_this.optionData[index].peisong_type_name);
							}



						})

						_this.ship_price = _this.ship_price
						_this.shipping_remark = '有电梯'



						// setTimeout(function() {
						// 	_this.open_sel_floor()
						// }, 400);


					}



				}
			},
			//选择楼层
			open_sel_floor(e) {
				// alert(JSON.stringify(e));
				let _this = this;
				let key = e.detail.value;

				// alert(key)
				_this.sel_floor = _this.floorList[key].id
				console.log("楼层", _this.sel_floor);
				if (key > -1) {
					var ship_price = 0
					var ship_string = ''

					_this.sel_floor = _this.floorList[key].id
					_this.sel_floor_name = _this.floorList[key].id
					console.log(_this.sel_service)
					if (_this.sel_service == 1) {
						// ship_price = (_this.total * res.selectedInfo[0].dianti * 0.01).toFixed(2)
						_this.ship_price = 0;
						console.log(_this.good_list)
						_this.optionData.forEach(function(el, index) {
							_this.current_price = (_this.optionData[index].current_price * _this.optionData[index]
								.good_num)
							console.log('有电梯--')
							console.log(_this.optionData[index].peisong_type_id)

							_this.getdiantiPrice(_this.floorList[key].id, _this.optionData[index].peisong_type_id,_this.optionData[index].peisong_type_name
								);


						})
						ship_string = '有电梯' + ',' + _this.floorList[key].louceng
					} else if (_this.sel_service == 2) {
						// ship_price = (_this.total * res.selectedInfo[0].nodianti * 0.01).toFixed(2)
						_this.ship_price = 0;
						_this.optionData.forEach(function(el, index) {
							_this.current_price = (_this.optionData[index].current_price * _this.optionData[index]
								.good_num)
							console.log('无电梯--')
							console.log(_this.optionData[index].peisong_type_id)
							_this.getnodiantiPrice(_this.floorList[key].id, _this.optionData[index].peisong_type_id,_this.optionData[index].peisong_type_name);


						})
						ship_string = '无电梯' + ',' + _this.floorList[key].louceng
					}
					// _this.ship_price = ship_price
					_this.shipping_remark = ship_string + '楼'
					console.log(_this.shipping_remark)
				}
			},

			async getdiantiPrice(louceng, peisong_type_id,peisong_type_name) {

				await uni.request({
					url: '/api/Good/peisong_price',
					method: 'POST',
					data: {
						peisong_type_name:peisong_type_name,
						peisong_type_id: peisong_type_id, //配送类型
						region_name: this.region_name,
						price: this.current_price,
						louceng: louceng + 1,
					},
					success: res => {
						this.sel_floor = louceng;
						// this.token = res.data.token;
						this.sel_price = res.data[0]
						console.log(res.data[0])
						console.log(222)
						console.log(res.data[1].price)
						console.log((res.data[1].price * this.sel_price.dianti * 0.01).toFixed(
							2))
						console.log(JSON.stringify(this.sel_price))
						this.ship_price += Number((res.data[1].price * this.sel_price.dianti *
							0.01).toFixed(2))
						console.log(this.ship_price)
					},
					// 1.1.6升级
					fail: res => {

					}
				});

			},

			async getnodiantiPrice(louceng, peisong_type_id,peisong_type_name) {

				await uni.request({
					url: '/api/Good/peisong_price',
					method: 'POST',
					data: {
						peisong_type_name:peisong_type_name,
						peisong_type_id: peisong_type_id, //配送类型
						region_name: this.region_name,
						price: this.current_price,
						louceng: louceng + 1,
					},
					success: res => {
						this.sel_floor = louceng;
						// this.token = res.data.token;
						this.sel_price = res.data[0]
						// console.log(222)
						// alert(JSON.stringify(this.sel_price))
						console.log((res.data[1].price * this.sel_price.nodianti * 0.01).toFixed(
							2))
						console.log(JSON.stringify(this.sel_price))
						this.ship_price += Number((res.data[1].price * this.sel_price.nodianti *
							0.01).toFixed(2))
					},
					// 1.1.6升级
					fail: res => {

					}
				});
			},
			async get_shipping() {
				await uni.request({
					url: '/api/Good/shipping_list_new',
					method: 'POST',
					data: {
						peisong_type_name:this.orderData.peisong_type_name, 
						peisong_type_id: this.orderData.peisong_type_id, //配送类型
						region_name: this.region_name,
						token: uni.getStorageSync("wanlshop:user").token
					},
					success: res => {
						// this.token = res.data.token;
						this.floorList = res.data
					},
					// 1.1.6升级
					fail: res => {

					}
				});

			},
			async loadData(address_id) {

				await uni.request({
					url: '/api/Order/getCreateOrderInfo',
					method: 'POST',
					data: {
						good_list: JSON.stringify(this.optionData),
						// flag: this.flag,
						address_id: address_id,
						token: uni.getStorageSync("wanlshop:user").token
					},
					success: res => {
						console.log(res.data)
						// this.token = res.data.token;
						this.orderData = res.data;
						console.log(this.orderData)

						if (res.data.goods_list) {
							this.getGoodslist = res.data.goods_list;
						} else {
							// this.addAddress('newadd');
						}
						
						if (res.data.good_address) {
							this.addressData = res.data.good_address;
						} else {
							// this.addAddress('newadd');
						}

						if (res.data.is_default_address == '1') {
							this.good_address = res.data.good_address
						}
						if (res.data.is_user_coupon != '0') {
							this.coupon_txt = res.data.is_user_coupon + '张优惠券可用'
						}
						if (res.data.is_used_gold == '1') {
							this.gold = res.data.gold
							this.gold_money = res.data.gold_money / 100
							// vm.gold_convert = ret.data.gold_convert
						}


						console.log(this.addressData)

						this.distance = res.data.distance;

						if (res.data.distance > 50) {
							uni.showModal({
								title: res.data.free_msg
							})
							// return;
						}
						if (res.data.freight_price > 0) {
							this.freight_price = res.data.freight_price / 100;
							uni.showModal({
								title: res.data.free_msg
							})
							// return;
						}

						this.get_shipping()
						// this.getdiantiPrice(1)

					},
					// 1.1.6升级
					fail: res => {
						if (res.msg == '请添加收货地址') {
							this.reload = true;
							this.userAddress()
							// this.addAddress('newadd');
						}
					}
				});
			},
			// 提交订单
			async addOrder() {
				// alert(this.remarks)
				// if(this.orderData.statis.allnum === 0){
				// 	this.$wanlshop.msg('订单异常')
				// 	return;
				// }
				let address_id = this.addressData.id;
				console.log(address_id)
				if (!this.addressData.id) {
					this.$wanlshop.msg('请填写地址')
					return;
				}
				//             alert(this.shipping_remark)
				// alert(this.shipping_type)
				if (!this.shipping_remark && this.shipping_type == 1) {
					this.$wanlshop.msg('请选择是否需要入户服务')
					return;
				}

				// alert(this.sel_service)
				// alert(this.sel_floor)
				if (this.sel_floor == -1 && this.sel_service > 0) {
					this.$wanlshop.msg('请选择楼层')
					return;
				}


				let data = {
						lists: [],
						address_id: address_id
					},
					cart = [];

				// this.optionData.forEach((item, index) => {
				// 	cart.push({
				// 		goods_id: item.id,
				// 		sku_id: item.sku_id
				// 	});
				// 	// 商品数据
				// 	data.lists.push({
				// 		goods_id: item.good_id,
				// 		number: item.good_num,
				// 		sku_id: item.sku_id,
				// 		good_price:item.cost_price
				// 	});

				// });
				// console.log(data.lists)

				// this.orderData.lists.forEach((item, index)=> {
				// 	data.lists.push({
				// 		shop_id: item.shop_id,
				// 		remarks: item.remarks,
				// 		products: [],
				// 		//店铺优惠券和其他 在下追加
				// 		coupon_id: this.couponData[index] ? this.couponData[index].id : 0
				// 	});
				// 	item.products.forEach(goods => {
				// 		// 购物车数据
				// 		cart.push({
				// 			goods_id: goods.id,
				// 			sku_id: goods.sku.id
				// 		});
				// 		// 商品数据
				// 		data.lists[index].products.push({
				// 			goods_id: goods.id,
				// 			number: goods.number,
				// 			sku_id: goods.sku.id,
				// 			freight_id: goods.freight_id
				// 		});
				// 	});
				// });

				this.loading = true;
				// 提交订单数据data
				await uni.request({
					url: '/api/Order/xcx_createOrder',
					method: 'POST',
					data: {
						good_list: JSON.stringify(this
							.optionData), //[{"good_id":"1","good_num":"2","good_sku":"40寸|红"}]
						flag: 2, //1标识详情页发起生成订单，2标识购物车发起生成订单
						address_id: address_id,
						token: uni.getStorageSync("wanlshop:user").token,
						miao_id: this.miao_id, //2022年4月9日21:06:09
						gold_price: this.is_used_gold == '1' ? this.gold_money : 0,
						gold: this.is_used_gold == '1' ? this.gold : 0,
						// ship_price: this.is_used_coupon == '0' ? this.orderData.exp_fee : 0,
						// ship_price: this.orderData.exp_fee,
						freight_price: this.freight_price * 100, //2022年4月5日07:55:00
						ship_price: this.ship_price * 100,
						shipping_remark: this.shipping_remark,
						shipping_type: this.shipping_type,
						is_used_coupon: this.is_used_coupon,
						user_coupon_id: this.user_coupon_id,
						remark: this.remarks,
						receipt_type: this.receipt_type == '未选择' ? '' : this.receipt_type,
						receipt_name: this.receipt_name,
						receipt_num: this.receipt_num,
						receipt_phone: this.receipt_phone,
						receipt_address: this.receipt_address,
						receipt_account: this.receipt_account,
						receipt_bank: this.receipt_bank,
						receipt_person: this.receipt_person,
						is_receipt: this.is_receipt,
						distance: this.distance, //2022年4月6日06:54:10
						// app_version: api.appVersion,
					},
					success: res => {

						//alert(JSON.stringify(res))
						console.log(res)
						// if (res.data.status == 0) {
						//                          uni.showToast({
						//                          	title: res.data.msg
						//                          })
						// 	   return;
						// }
						console.log(res.data)
						let orderinfo = res.data;

						// alert(JSON.stringify(this.optionData))
						this.optionData.forEach((item, index) => {
							// state.good_cart_ids.push(item.id)
							cart.push({
								goods_id: item.good_id,
								id: item.id,
								sku_id: item.sku_id
							});

							// 商品数据
							data.lists.push({
								goods_id: item.good_id,
								number: item.good_num,
								sku_id: item.sku_id,
								good_price: item.current_price,
								ship_price: this.ship_price,
								freight_price: this.freight_price,
								order_no: orderinfo.order_num,
								order_id: orderinfo.order_id,
							});

						});
						// alert(JSON.stringify(cart))
						console.log(data.lists)

						// this.$store.commit('statistics/order', {
						// 	pay: this.$store.state.statistics.order.pay + res.data.list.length,
						// 	whole: this.$store.state.statistics.order.whole + res.data.list.length
						// });
						// 如果使用优惠券全局减去
						// let coupon = Object.keys(this.couponData).length;
						// if (coupon != 0) {
						// 	this.$store.commit('statistics/dynamic', {
						// 		coupon: this.$store.state.statistics.dynamic.coupon - coupon
						// 	});
						// }
						// 大厂软件，就是这么迷幻
						if (this.cartType == 'cart') {

							this.$store.dispatch('cart/delAll', cart);
						}

						uni.redirectTo({
							url: `/pages/user/money/pay?order_id=${orderinfo.order_id}&data=${JSON.stringify(data.lists)}&amount=` +
								this.amount
						})

					}
				});
			},
			//添加或修改成功之后回调
			async refreshList(data, type) {
				// alert(JSON.stringify(data))
				await uni.request({
					url: '/api/Address/addAddress',
					method: 'POST',
					data: {
						username: data.username,
						mobile: data.mobile,
						province_id: data.province_id,
						province_name: data.province_name,
						city_id: data.city_id,
						city_name: data.city_name,
						area_id: data.area_id,
						area_name: data.area_name,
						address: data.address,
						detailed_address: data.detailed_address,
						is_default: data.is_default,
						type: 'add',
						token: uni.getStorageSync("wanlshop:user").token
					},
					success: res => {
						this.addressData = res.data;
						// 1.1.6升级
						if (this.reload) {
							this.loadData();
						}
					}
				});
			},
			// 查询优惠券，减缓服务器压力，单独查询（仅查询首次）
			async queryCoupon() {
				await uni.request({
					url: '/api/Coupon/choiceCouponList',
					method: 'POST',
					data: {
						token: uni.getStorageSync("wanlshop:user").token,
						price: this.amount
					},
					success: res => {
						this.couponList = res.data;
					}
				});
				this.modalName = 'coupon';
			},
			// 领取优惠券
			async onReceive(index) {
				let coupon = this.orderData.lists[this.couponIndex].coupon[index];
				await uni.request({
					url: '/wanlshop/coupon/receive',
					method: 'POST',
					data: {
						id: coupon.id
					},
					success: res => {
						coupon.id = res.data.id;
						coupon.state = true;
						this.$wanlshop.msg(res.data.msg);
						this.$store.commit('statistics/dynamic', {
							coupon: this.$store.state.statistics.dynamic.coupon + 1
						});
					}
				});
			},
			// 选中优惠券, 将优惠券放进数组中
			onCoupons(coupon_id, money) {
				this.is_used_coupon = 1;
				this.user_coupon_id = coupon_id
				this.coupon_txt = '已使用1张优惠券'
				if (money == 0) {
					this.coupon_money = this.orderData.exp_fee / 100;
				} else {
					this.coupon_money = money;
				}
				this.hideModal();


				// let order = this.orderData.lists[this.couponIndex];
				// let data = this.orderData.lists[this.couponIndex].coupon;
				// data[index].choice = !data[index].choice;
				// if (data[index].choice) {
				// 	// 遍历取消掉其他选择的状态，for性能高于其他历遍
				// 	for (var i = 0; i < data.length; i++) {
				// 		if (i != index) {
				// 			data[i].choice = false;
				// 		}
				// 	};
				// 	// 更新选择
				// 	this.couponData[this.couponIndex] = data[index];
				// 	// @ 精度计算 this.$wanlshop.bcadd('0.132123',0.132123)
				// 	// 满减计算
				// 	if (data[index].type == 'reduction' || (data[index].type == 'vip' && data[index].usertype ==
				// 			'reduction')) {
				// 		order.freight.price = order.freight_price_bak;
				// 		order.sub_price = this.$wanlshop.bcsub(this.$wanlshop.bcadd(order.order_price, order.freight
				// 			.price), data[index].price);
				// 		if (order.sub_price < 0) {
				// 			order.sub_price = 0.01;
				// 		}
				// 	}
				// 	// 折扣计算  前端出问题
				// 	if (data[index].type == 'discount' || (data[index].type == 'vip' && data[index].usertype ==
				// 			'discount')) {
				// 		let discount = data[index].discount > 10 ? this.$wanlshop.bcdiv(data[index].discount, 100) : this
				// 			.$wanlshop.bcdiv(data[index].discount, 10);
				// 		order.freight.price = order.freight_price_bak;
				// 		order.sub_price = this.$wanlshop.bcadd(this.$wanlshop.bcmul(order.order_price, discount), order
				// 			.freight.price);
				// 	}
				// 	// 包邮计算
				// 	if (data[index].type == 'shipping') {
				// 		order.freight.price = 0;
				// 		order.sub_price = order.order_price;
				// 	}
				// } else {
				// 	// 恢复原价 1.0.2升级
				// 	this.couponData = {};
				// 	if (data[index].type == 'shipping') {
				// 		order.freight.price = order.freight_price_bak;
				// 	}
				// 	order.sub_price = this.$wanlshop.bcadd(order.order_price, order.freight.price);
				// }
				// // 精度计算合计
				// this.orderData.statis.allsub = 0;
				// for (var i = 0; i < this.orderData.lists.length; i++) {
				// 	this.orderData.statis.allsub = this.$wanlshop.bcadd(this.orderData.statis.allsub, this.orderData.lists[
				// 		i].sub_price);
				// };
				// this.modalName = null;
				// alert(this.modalName)
			},
			// 修改数量
			changeNum(num) {
				num = num == 0 ? 1 : num;
				this.orderData.lists[0].number = num;
				this.orderData.lists[0].products[0].number = num;
				// this.orderData.statis.allnum = num;
				// 计算价格
				this.orderData.lists[0].sub_price = this.$wanlshop.bcmul(this.orderData.lists[0].products[0].sku.price,
					num);
				this.orderData.statis.allsub = this.$wanlshop.bcmul(this.orderData.lists[0].products[0].sku.price, num);
			},
			addAddress(type) {
				this.$wanlshop.to(`/pages/user/address/addressManage?type=${type}`);
			},
			userAddress() {
				this.sel_service = -1;
				this.ship_price = 0;
				this.freight_price = 0;
				this.shipping_type = 1;
				this.shipping_remark = '';
				this.$wanlshop.to('/pages/user/address/address?source=1');
			},
			// 弹出层，暂时不需要但后续版本可能需要
			showModal(name) {
				this.modalName = name;
			},
			// 关闭弹出层
			hideModal() {
				this.modalName = null;
			},
			// 数组去重并字符串
			unique(arr) {
				return Array.from(new Set(arr)).join(',');
			},
			//禁止父元素滑动
			moveHandle() {}
		}
	};
</script>

<style>
	.gold_opt img {
		width: 2.25rem;
		height: 1.5rem;
		float: right;
	}
</style>